#include "Light.h"
#include "Vec3.h"

Light::Light(int LightID)
{
	m_Id = LightID;
	m_IsOn = false;
}

GLvoid Light::SetDirection(GLfloat x, GLfloat y, GLfloat z, GLfloat type)
{
	// 0 is directional
	// 1 is positional
	// TODO find out the other types of possible lights
	m_IsPositional = type;
	m_Position[0] = x;
	m_Position[1] = y;
	m_Position[2] = z;
	m_Position[3] = type;
}

GLvoid Light::SetAmbient(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
	m_Ambient[0] = r;
	m_Ambient[1] = g;
	m_Ambient[2] = b;
	m_Ambient[3] = a;
}

GLvoid Light::SetDiffuse(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
	m_Diffuse[0] = r;
	m_Diffuse[1] = g;
	m_Diffuse[2] = b;
	m_Diffuse[3] = a; 
}

GLvoid Light::SetSpecular(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
	m_Specular[0] = r;
	m_Specular[1] = g;
	m_Specular[2] = b;
	m_Specular[3] = a; 
}


GLvoid Light::SpotLight(Vec3 CarPos)
{
	//GLfloat CarPosArray[] = {CarPos.x, CarPos.y, CarPos.z};
	//glLightfv(m_Id, GL_SPOT_DIRECTION, CarPosArray);
}

void Light::Use()
{
	glColor3f(1, 1, 1);
	//Set Position
	glLightfv(m_Id, GL_POSITION, m_Position);
	//Set Ambient
	glLightfv(m_Id, GL_AMBIENT, m_Ambient);
	//Set Diffuse
	glLightfv(m_Id, GL_DIFFUSE, m_Diffuse);
	//Set Specular
	glLightfv(m_Id, GL_SPECULAR, m_Specular);
	m_IsOn = true;
}

void Light::Enable()
{
	if(!m_IsOn)
	{
		glEnable(m_Id);
		m_IsOn = true;
	}

}
void Light::Disable()
{
	if(m_IsOn)
	{
		glDisable(m_Id);
		m_IsOn = false;
	}
}

bool Light::IsOn()
{
	return m_IsOn;
}